package com.example.springboot.mapper;

import com.example.springboot.entity.Companies;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EnterpriseMapper {

    @Select("select * from companies")
    List<Companies> findAll();

    @Insert("INSERT INTO companies (company_name, contact_info, business_type) " +
            "VALUES (#{company_name}, #{contact_info}, #{business_type})")
    void addCompany(Companies company);

    @Update("update companies set company_name=#{company_name}, industry=#{industry},  website=#{website},  description=#{description},  contact_person=#{contact_person}, " +
            " contact_email=#{contact_email},  contact_phone=#{contact_phone} ,address=#{address} where company_id=#{company_id}")
    void editCompany(Companies company);

    @Delete("DELETE FROM companies WHERE company_id=#{company_id}")
    void deleteCompany(int company_id);

    @Delete({
            "<script>",
            "DELETE FROM companies WHERE company_id IN ",
            "<foreach item='company_id' collection='list' open='(' separator=',' close=')'>#{company_id}</foreach>",
            "</script>"
    })
    void deleteCompanyBatch(List<Long> ids);

    @Select("select * from companies where company_name LIKE CONCAT('%', #{company_name}, '%') ")
    List<Companies> selectByName(String company_name);
}